package bold.storage.splice;


public class StrKit {
    public static final char UNDERLINE = '_';

    public StrKit() {
    }

    /**
     * 首字母转小写
     */
    public static String firstCharToLowerCase(String str) {
        char firstChar = str.charAt(0);
        if (firstChar >= 65 && firstChar <= 90) {
            char[] arr = str.toCharArray();
            arr[0] = (char) (arr[0] + 32);
            return new String(arr);
        } else {
            return str;
        }
    }

    /**
     * 首字母转大写
     */
    public static String firstCharToUpperCase(String str) {
        char firstChar = str.charAt(0);
        if (firstChar >= 97 && firstChar <= 122) {
            char[] arr = str.toCharArray();
            arr[0] = (char) (arr[0] - 32);
            return new String(arr);
        } else {
            return str;
        }
    }

    /**
     * 驼峰 转换 下划线
     *
     * @param param
     * @return
     */
    public static String camelToUnderline(String param) {
        if (param == null || "".equals(param.trim())) {
            return "";
        }
        int len = param.length();
        StringBuilder sb = new StringBuilder(len);
        for (int i = 0; i < len; i++) {
            char c = param.charAt(i);
            if (Character.isUpperCase(c)) {
                sb.append(UNDERLINE);
                sb.append(Character.toLowerCase(c));
            } else {
                sb.append(c);
            }
        }
        return sb.toString();
    }

    /**
     * 下划线格式 转换  驼峰
     */
    public static String underlineToCamel(String param) {
        if (param == null || "".equals(param.trim())) {
            return "";
        }
        int len = param.length();
        StringBuilder sb = new StringBuilder(len);
        for (int i = 0; i < len; i++) {
            char c = param.charAt(i);
            if (c == UNDERLINE) {
                if (++i < len) {
                    sb.append(Character.toUpperCase(param.charAt(i)));
                }
            } else {
                sb.append(c);
            }
        }
        return sb.toString();
    }

    public static String concat(String... str) {
        return concat(null, str);
    }

    public static String concat(String wrap, String[] str) {
        StringBuilder sb = new StringBuilder();
        String[] var3 = str;
        int var4 = str.length;

        for (int var5 = 0; var5 < var4; ++var5) {
            Object s = var3[var5];
            if (wrap != null) {
                sb.append(wrap).append(String.valueOf(s)).append(wrap).append(",");
            } else {
                sb.append(String.valueOf(s)).append(",");
            }
        }

        return removeLastComma(sb).toString();
    }

    public static StringBuilder removeLastComma(StringBuilder sb) {
        if (sb != null && sb.length() != 0) {
            if (sb.charAt(sb.length() - 1) == 44) {
                sb.deleteCharAt(sb.length() - 1);
            }

            return sb;
        } else {
            return sb;
        }
    }
}
